#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
SVG图标生成器
为微信小程序生成所需的图标
"""

import os
import json

class IconGenerator:
    def __init__(self):
        self.icons_dir = "generated_icons"
        os.makedirs(self.icons_dir, exist_ok=True)
    
    def generate_tabbar_icons(self):
        """生成底部导航栏图标"""
        icons = {
            'home': {
                'name': '首页',
                'path': 'M10 20V14H14V20H19V12H22L12 3L2 12H5V20H10Z'
            },
            'category': {
                'name': '分类',
                'path': 'M4 6H6V8H4V6ZM4 10H6V12H4V10ZM4 14H6V16H4V14ZM8 6H20V8H8V6ZM8 10H20V12H8V10ZM8 14H20V16H8V14Z'
            },
            'cart': {
                'name': '购物车',
                'path': 'M7 18C5.9 18 5.01 18.9 5.01 20S5.9 22 7 22 9 21.1 9 20 8.1 18 7 18ZM1 2V4H3L6.6 11.59L5.24 14.04C5.09 14.32 5 14.65 5 15C5 16.1 5.9 17 7 17H19V15H7.42C7.28 15 7.17 14.89 7.17 14.75L7.2 14.63L8.1 13H15.55C16.3 13 16.96 12.58 17.3 11.97L20.88 5H5.21L4.27 2H1ZM17 18C15.9 18 15.01 18.9 15.01 20S15.9 22 17 22 19 21.1 19 20 18.1 18 17 18Z'
            },
            'profile': {
                'name': '我的',
                'path': 'M12 12C14.21 12 16 10.21 16 8C16 5.79 14.21 4 12 4C9.79 4 8 5.79 8 8C8 10.21 9.79 12 12 12ZM12 14C9.33 14 4 15.34 4 18V20H20V18C20 15.34 14.67 14 12 14Z'
            }
        }
        return icons
    
    def generate_functional_icons(self):
        """生成功能图标"""
        icons = {
            'search': {
                'name': '搜索',
                'path': 'M15.5 14H14.71L14.43 13.73C15.41 12.59 16 11.11 16 9.5C16 5.91 13.09 3 9.5 3S3 5.91 3 9.5S5.91 16 9.5 16C11.11 16 12.59 15.41 13.73 14.43L14 14.71V15.5L19 20.49L20.49 19L15.5 14ZM9.5 14C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5S14 7.01 14 9.5S11.99 14 9.5 14Z'
            },
            'heart': {
                'name': '收藏',
                'path': 'M12 21.35L10.55 20.03C5.4 15.36 2 12.28 2 8.5C2 5.42 4.42 3 7.5 3C9.24 3 10.91 3.81 12 5.09C13.09 3.81 14.76 3 16.5 3C19.58 3 22 5.42 22 8.5C22 12.28 18.6 15.36 13.45 20.04L12 21.35Z'
            },
            'heart_outline': {
                'name': '收藏（空心）',
                'path': 'M20.84 4.61A5.5 5.5 0 0 0 16.5 3C14.76 3 13.09 3.81 12 5.09C10.91 3.81 9.24 3 7.5 3A5.5 5.5 0 0 0 3.16 4.61C1.84 5.95 1.84 8.05 3.16 9.39L12 18.23L20.84 9.39C22.16 8.05 22.16 5.95 20.84 4.61Z'
            },
            'plus': {
                'name': '添加',
                'path': 'M19 13H13V19H11V13H5V11H11V5H13V11H19V13Z'
            },
            'minus': {
                'name': '减少',
                'path': 'M19 13H5V11H19V13Z'
            },
            'close': {
                'name': '关闭',
                'path': 'M19 6.41L17.59 5L12 10.59L6.41 5L5 6.41L10.59 12L5 17.59L6.41 19L12 13.41L17.59 19L19 17.59L13.41 12L19 6.41Z'
            },
            'arrow_right': {
                'name': '右箭头',
                'path': 'M8.59 16.59L13.17 12L8.59 7.41L10 6L16 12L10 18L8.59 16.59Z'
            },
            'arrow_left': {
                'name': '左箭头',
                'path': 'M15.41 16.59L10.83 12L15.41 7.41L14 6L8 12L14 18L15.41 16.59Z'
            },
            'location': {
                'name': '位置',
                'path': 'M12 2C8.13 2 5 5.13 5 9C5 14.25 12 22 12 22S19 14.25 19 9C19 5.13 15.87 2 12 2ZM12 11.5C10.62 11.5 9.5 10.38 9.5 9S10.62 6.5 12 6.5S14.5 7.62 14.5 9S13.38 11.5 12 11.5Z'
            },
            'phone': {
                'name': '电话',
                'path': 'M6.62 10.79C8.06 13.62 10.38 15.94 13.21 17.38L15.41 15.18C15.69 14.9 16.08 14.82 16.43 14.93C17.55 15.3 18.75 15.5 20 15.5C20.55 15.5 21 15.95 21 16.5V20C21 20.55 20.55 21 20 21C10.61 21 3 13.39 3 4C3 3.45 3.45 3 4 3H7.5C8.05 3 8.5 3.45 8.5 4C8.5 5.25 8.7 6.45 9.07 7.57C9.18 7.92 9.1 8.31 8.82 8.59L6.62 10.79Z'
            }
        }
        return icons
    
    def save_icons_data(self):
        """保存图标数据到JSON文件"""
        tabbar_icons = self.generate_tabbar_icons()
        functional_icons = self.generate_functional_icons()
        
        all_icons = {**tabbar_icons, **functional_icons}
        
        json_path = os.path.join(self.icons_dir, 'icons_data.json')
        with open(json_path, 'w', encoding='utf-8') as f:
            json.dump(all_icons, f, ensure_ascii=False, indent=2)
        
        print(f"图标数据已保存到: {json_path}")
        return all_icons

def main():
    """主函数"""
    print("=== SVG图标生成器 ===")
    
    generator = IconGenerator()
    icons = generator.save_icons_data()
    
    print(f"共生成 {len(icons)} 个图标:")
    for name, data in icons.items():
        print(f"  - {name}: {data['name']}")

if __name__ == "__main__":
    main()